//
//  LDExpressLoginVC.swift
//  DingDongZP
//
//  Created by Zhongnan on 16/6/29.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

import UIKit

class LDExpressLoginVC: LDLoginBaseVC {

    override func viewDidLoad() {
        
        super.viewDidLoad()
        
    }
    
    //点击进入
    override func enterClick() {
        
        let phone = phoneTextField.text ?? ""
        let code = securityCodeTextField.text ?? ""
        
        let params = ["mobile":phone,"code":code]
        
        LDCheckPublicInfo.shareInstance.expressLogin(params, succ: { [weak self](value) in
            
            let isNew = value["is_newUser"] as? Int ?? 0
            
            if isNew == 1 {
                
                LDShowHUB.shareInstance.showToastNoti("随机密码已通过短信发送")
            }
            
//            let rawPassword = value["newUserPassword"] as? String ?? ""
            let hashPassword = value["hashed_password"] as? String ?? ""
            
            DDLoginUserManager.setAccount(self?.phoneTextField.text)
            DDLoginUserManager.setToken(hashPassword)
         
            let agreement = DDChoosePositonViewController()
            self?.navigationController?.pushViewController(agreement, animated: true)
            
            
        }) { (data) in
            
            let notice = data as? String ?? "注册失败"
            LDShowHUB.shareInstance.showBarStatus(notice)
        }
    }
    
    override func changStatus(btn: UIButton) {
        
       if btn.tag == securitytag {//获取验证码
        
            getcodeBtn.userInteractionEnabled = false
            requestCodeNet()
        }
    }
    
    override func setupDefaultContent() {
        
        super.setupDefaultContent()

        enterBtn.setTitle("快捷登录", forState: .Normal)
        passwordTextField.hidden = true
        
        let loginLab = UILabel.setDetailsLab("密码登录", fontSize: 16, titleColor: LDFontColor.GreenLight, Alignment: .Right)
        loginLab.userInteractionEnabled = true
        view.addSubview(loginLab)
        
        
        loginLab.bk_whenTapped { [weak self] in
            self?.navigationController?.popViewControllerAnimated(true)
        }
        
        loginLab.snp_makeConstraints { (make) in
            make.top.equalTo(enterBtn.snp_bottom).offset(10)
            make.right.equalTo(enterBtn)
            make.height.equalTo(16)
        }
        
        
        passwordTextField.snp_updateConstraints { (make) in
            
            make.size.equalTo(CGSizeZero)
        }

        securityCodeTextField.snp_updateConstraints { (make) in
            
            make.top.equalTo(phoneTextField.snp_bottom).offset(15)
        }
        
        view.layoutIfNeeded()
        
    }
    
    override func keyboardHidden(noti: NSNotification?) {
        super.keyboardHidden(noti)
        navigationItem.title = ""
        
    }
    
    override func keyboardShow(noti: NSNotification) {
        super.keyboardShow(noti)
        navigationItem.title = "快捷登录"
    }
    
}
